<!DOCTYPE html>
<html lang="en">
<head>
    <?php
    unset($_SESSION['user']);
    ?>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>你好，公众号</title>
  <script src="https://cdn.jsdelivr.net/npm/babel-polyfill/dist/polyfill.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/jquery"></script>
  <script src="__PUBLIC__/script/layer/layer.js"></script>
  <script src="__PUBLIC__/node_modules/datatables/media/js/jquery.dataTables.min.js"></script>

  <script src="__PUBLIC__/script/bootstrap-treeview-master/dist/bootstrap-treeview.min.js"></script>
  <link rel="stylesheet" href="__PUBLIC__/script/bootstrap-treeview-master/dist/bootstrap-treeview.min.css">
  <link rel="stylesheet" href="__PUBLIC__/node_modules/bootstrap/dist/css/bootstrap.min.css">
  <link rel="stylesheet" href="__PUBLIC__/style/base.css">
  <link rel="stylesheet" href="__PUBLIC__/style/manage.css">
  <link rel="stylesheet" href="__PUBLIC__/style/manage_zizhanghao.css">
  <style>
    /* .authSetting,.lookin {
      text-align: center;
    } */
    .lookin_img { width:1.5rem;height:1.5rem;display: inline-block; }
    .lookin_img img{ width:100%; }
  </style>
</head>
<body>
  <div style='display:none;'>
    <input type="hidden" name="提交三傻选项" id="postThisLine" value="{:U('WebUser/re_qaf')}">
  </div>
  <div class="container-fluid">
    <div class="row">
      <header class="col-xs-6 col-md-2 account_name"><img class='img-responsive' src="__PUBLIC__/images/logo_long.jpg" alt=""></header>
      <div class="col-xs-12 col-md-12">
        <div class="row">

          <!-- 左侧栏 -->
          <div class="col-md-2 manage_nav_box">
            <iframe src="{:U('Managezi/nav_qudao')}?local=zizhanghao_m" frameborder="0" width="100%" style="height:15rem;"></iframe>

            <!-- 账号选项 -->
            <div class="account_option">
              <a href="{:U('index/update_passwd')}" class="pass_mod">修改密码</a>
              <a href="{:U('index/loginout')}" class="sign_out">退出登录</a>
            </div>
            <!-- end 账号选型 -->
          </div>
          <!-- end 左侧栏 -->

          <!-- 右主体  -->
          <div class="col-md-10 col-md-10 messageBox">



            <!-- begin  授权地区列表列表 -->
            <header>所有子账号列表</header>
            <!-- end 表头 -->

            <table class="messageBoxContent table table-striped table-bordered" id="main_table">
                <thead>
                  <tr>
                    <th class="authNo">序号</th>
                    <th class="logo">Logo</th>
                    <th class="ciji">子账号名称</th>
                    <!-- <th class="renshu">共有人数</th> -->
                    <th class="shouquan_people">授权人</th>
                    <th class="phone">电话</th>
                    <th class="pass">密码</th>
                    <th class="mail">邮箱</th>
                    <th class="authSetting">多选 <input type="checkbox" name="test" id="fuck" form='not_submit'></th>
                    <th class="lookin">设置</th>
                  </tr>
                </thead>
                <tbody>
                  <volist name="list" id='vo'>
                  <tr>
                    <td class="authNo">{$key+1}</td>
                    <if condition='$vo.login_img neq null'>
                    <td class="logo"><span class="table_logo"><a href = "{:U('next_m')}?u={$vo.u_id}"><img src="__ROOT__/{$vo.login_img}" alt="u636"></a></span></td>
                    <else />
                    <td class="logo"><span class="table_logo"><a href = "{:U('next_m')}?u={$vo.u_id}"><img src="__PUBLIC__/images/dengluye/u636.png" alt="u636"></a></span></td>
                    </if>

                    <td class="ciji">{$vo.u_name}</td>
                    <!-- -{$vo.u_city_id|re_data}-{$vo.u_area_id|re_data} -->
                    <!-- <td class="renshu">{$vo.u_id|re_num_ye}人</td> -->
                    <th class="shouquan_people">{$vo.u_pow_name}</th>
                    <th class="phone">{$vo.u_phone}</th>
                    <th class="pass">{$vo.u_pass}</th>
                    <th class="mail">{$vo.u_email}</th>
                    <td class="authSetting"><input type="checkbox" name="id_arr[]" value='{$vo.u_id}' id="diqu_1" form="delete_form"></td>
                    <!-- <td class="lookin"><a class="lookin_img" href = "{:U('next_m')}?u={$vo.u_id}"><img src="__PUBLIC__/images/dengluye/u41.png" alt="u41"></a></td> -->
                    <td class="lookin"><a class="lookin_img" href = "javascript:;" inori-id='{$vo.u_id}' inori-ck-qudao='{$vo.ck_qudao}' inori-ck-fenxiao='{$vo.ck_fenxiao}' inori-ck-aj='{$vo.ck_aj}'><img src="__PUBLIC__/images/dengluye/u41.png" alt="u41"></a></td>
                  </tr>
                 </volist>

                </tbody>
              </table>
            <!-- end 授权地区列表列表 -->

            <!-- begin 删除选项（表单） -->
            <div class="form">
              <form autocomplete="off" action="{:U('Managezi/manage_zizhanghao')}" id="delete_form" method="POST">
                <input type="submit" value="删除所选" class="delete_all">
                <input type="reset" value="取消选择" class="reset_all">
              </form>
            </div>
            <!-- end 删除选项（表单） -->

            <!-- begin 分页 -->
            <div class="authPage">
              <!-- 页面指示器 -->
              <!-- <div class="pages">24/{$count}</div> -->
              <!-- 分页列表 -->
              <!-- <span class="number">...</span> -->
              <div class="pageList">
                {$page}
              </div>
            </div>
            <!-- end 分页 -->

          </div>
          <!-- end 右主体 -->

        </div>
      </div>
    </div>
  </div>
  <script>
    $(document).ready(function() {
      var proList = $('#main_table').DataTable({
        "paging": false,
        "info": false,
        "searching": false
      })
      $('.messageBoxContent thead .authSetting').on('click', function (event) {
        event.stopPropagation()
        Array.from($('.messageBoxContent input[type=\'checkbox\']')).forEach(function(val,index){val.checked = !val.checked})
      })
    })
    window.addEventListener('message', fromNav, false)
    function fromNav(event) {
      console.log(event.data.url)
      if (event.data.url.length && event.data.url.length > 1) {
        self.location = event.data.url
      }
    }

    // 弹层设置
    $(document).ready(() => {
      function postThisPopup (evt) {
        const lineID = $(evt.target).attr('inori-id')
        const ckQudao = $(`#popup_qudao`).prop('checked') ? '0' : '1'
        const ckFenxiao = $(`#popup_fenxiao`).prop('checked') ? '0' : '1'
        const ckAj = $(`#popup_anjie`).prop('checked') ? '0' : '1'
        const ajaxData = {
          u_id: lineID,
          ck_qudao: ckQudao,
          ck_fenxiao: ckFenxiao,
          ck_aj: ckAj
        }
        const AjaxURL = String($('#postThisLine').val())
        $.ajax(AjaxURL, {
          method: 'post',
          data: ajaxData
        }).done((res) => {
          if (res.code && String(res.code) === '1') {
            alert(`修改成功`)
            layer.closeAll()
            location.reload()
          } else {
            $(`#popup_btn`).one({click: postThisPopup}, evt.data)
            alert(`修改失败！服务器返回：${res.message}`)
          }
        }).fail((err) => {
          $(`#popup_btn`).one({click: postThisPopup}, evt.data)
          alert(`网络测试失败！请检查玩咯`)
          throw err
        })
      }
      $(`.lookin_img`).each((index, item) => {
        $(item).on('click', (evt) => {
          evt.stopPropagation()
          evt.preventDefault()
          // inori-ck-qudao='{$vo.ck_qudao}' inori-ck-fenxiao='{$vo.ck_fenxiao}' inori-ck-aj='{$vo.ck_aj}'
          const lineID = $(evt.target).closest('a').attr('inori-id')
          const ckQudao = $(evt.target).closest('a').attr('inori-ck-qudao')
          const ckFenxiao = $(evt.target).closest('a').attr('inori-ck-fenxiao')
          const ckAj = $(evt.target).closest('a').attr('inori-ck-aj')
          const templ = `
            <div style='text-align:left;'>
              <div style='width:20rem;margin:.5rem 20px;font-size:1.6rem;'>
                <label><input type="checkbox" name="popup_qudao" id="popup_qudao" style='-webkit-appearance:checkbox;margin-right:5px;' ${ckQudao === '0' ? 'checked' : ''}>可以添加自己的渠道</label>
              </div>
              <div style='width:20rem;margin:.5rem 20px;font-size:1.6rem;'>
                <label><input type="checkbox" name="popup_fenxiao" id="popup_fenxiao" style='-webkit-appearance:checkbox;margin-right:5px;' ${ckFenxiao === '0' ? 'checked' : ''}>可以使用分销功能</label>
              </div>
              <div style='width:20rem;margin:.5rem 20px;font-size:1.6rem;'>
                <label><input type="checkbox" name="popup_anjie" id="popup_anjie" style='-webkit-appearance:checkbox;margin-right:5px;' ${ckAj === '0' ? 'checked' : ''}>必须使用公用按揭员</label>
              </div>
              <div id='popup_btn' inori-id='${lineID}' style='display:none;margin:.5rem auto;text-align:center;font-weight:700;width: 158px;line-height: 40px;color: #fff;background-color: #007cb8;font-size:1.6rem;'>
                保存变更
              </div>
            </div>
          `
          if (lineID === '') {
            throw new Error(`用户不存在ID，严重错误，请联系后台管理员`)
          }
          //页面层-自定义
          layer.open({
            type: 1,
            title: false,
            closeBtn: 0,
            title: '设置本账号',
            area: ['400px', '300px'],
            shadeClose: true,
            // skin: 'yourclass',
            content: templ
          });
          // 异步开启显示，但是dom已经存在
          $(`#popup_fenxiao`).one('change', (evt) => {
            $(`#popup_btn`).css(`display`, 'block')
          })
          $(`#popup_qudao`).one('change', (evt) => {
            $(`#popup_btn`).css(`display`, 'block')
          })
          $(`#popup_anjie`).one('change', (evt) => {
            $(`#popup_btn`).css(`display`, 'block')
          })
          $(`#popup_btn`).one({click: postThisPopup}, {})
        })
      })
    })
  </script>
</body>
</html>
